import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";

import { Repository } from "typeorm";

import {
  User,
  UserGateway,
  UserWeChat,
  UserWechatGateway,
  UserEmail,
  UserEmailGateway,
  UserPassword,
  UserPasswordGateway,
  RefUserSub,
  RefUserSubGateway,
} from "qqlx-core";
import { UserSchema, RefUserSubSchema, UserWeChatSchema, UserEmailSchema, UserPasswordSchema } from "qqlx-cdk";

import { PgDaoUUid } from "../../lib/dao.pg.uuid";
import { PgDao } from "../../lib/dao.pg.id";

@Injectable()
export class UserDao extends PgDaoUUid<User> {
  constructor(
    @InjectRepository(UserSchema)
    readonly repo: Repository<User>,
  ) {
    super({
      repository: repo,
      relations_name: UserGateway.relations,
    });
  }
}

// RefUserSub

@Injectable()
export class RefUserSubDao extends PgDao<RefUserSub> {
  constructor(
    @InjectRepository(RefUserSubSchema)
    readonly repo: Repository<RefUserSub>,
  ) {
    super({
      repository: repo,
      relations_name: RefUserSubGateway.relations,
    });
  }
}

// UserPassword

@Injectable()
export class UserPasswordDao extends PgDao<UserPassword> {
  constructor(
    @InjectRepository(UserPasswordSchema)
    readonly repo: Repository<UserPassword>,
  ) {
    super({
      repository: repo,
      relations_name: UserPasswordGateway.relations,
    });
  }
}

// UserWeChat

@Injectable()
export class UserWeChatDao extends PgDao<UserWeChat> {
  constructor(
    @InjectRepository(UserWeChatSchema)
    readonly repo: Repository<UserWeChat>,
  ) {
    super({
      repository: repo,
      relations_name: UserWechatGateway.relations,
    });
  }
}

// UserEmail

@Injectable()
export class UserEmailDao extends PgDao<UserEmail> {
  constructor(
    @InjectRepository(UserEmailSchema)
    readonly repo: Repository<UserEmail>,
  ) {
    super({
      repository: repo,
      relations_name: UserEmailGateway.relations,
    });
  }
}
